<?php

/**
 * This is the model class for table "{{proveedores}}".
 *
 * The followings are the available columns in table '{{proveedores}}':
 * @property integer $idproveedores
 * @property string $ruc
 * @property string $tipo_persona
 * @property string $razon_social
 * @property string $correo
 * @property string $contacto
 *
 * The followings are the available model relations:
 * @property Alertas[] $alertases
 */
class Proveedor extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Proveedor the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{proveedores}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ruc, tipo_persona, razon_social, correo', 'required'),
			array('ruc', 'length', 'max'=>13),
			array('tipo_persona', 'length', 'max'=>45),
			array('razon_social, correo', 'length', 'max'=>250),
			array('contacto', 'length', 'max'=>300),
			array('ruc','unique'),
			array('correo','email','allowEmpty'=>'false'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idproveedores, ruc, tipo_persona, razon_social, correo, contacto', 'safe', 'on'=>'search'),
		);
		
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'alertases' => array(self::HAS_MANY, 'Alertas', 'proveedor'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idproveedores' => 'ID : ',
			'ruc' => 'RUC : ',
			'tipo_persona' => 'TIPO : ',
			'razon_social' => 'RAZÓN SOCIAL : ',
			'correo' => 'CORREO : ',
			'contacto' => 'CONTACTO : ',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idproveedores',$this->idproveedores);
		$criteria->compare('ruc',$this->ruc,true);
		$criteria->compare('tipo_persona',$this->tipo_persona,true);
		$criteria->compare('razon_social',$this->razon_social,true);
		$criteria->compare('correo',$this->correo,true);
		$criteria->compare('contacto',$this->contacto,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}